package com.plat.net.http;


import com.plat.net.http.handler.DispatchHandler;
import com.plat.net.http.handler.FileUploadHandler;
import com.plat.net.http.handler.HttpHandler;
import com.plat.net.http.handler.WebSocketHandler;
import com.plat.net.http.ioc.annotation.core.AnnotationConfigContainer;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.logging.LoggingHandler;
import io.netty.handler.stream.ChunkedWriteHandler;

/**
 * 初始化管道处理器
 */
public class HttpChannelInitial extends ChannelInitializer<SocketChannel> {
    //初始化容器

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast("logging", new LoggingHandler("DEBUG"));//设置log监听器，并且日志级别为debug，方便观察运行流程
//        pipeline.addLast("protocol",new DymProtocol());//协议解析器
        pipeline.addLast("http-codec", new HttpServerCodec());//设置解码器
        pipeline.addLast("aggregator", new HttpObjectAggregator(65536));//聚合器，使用websocket会用到
        pipeline.addLast("dispatch", new DispatchHandler());//设置chunked编码器
        ch.pipeline().addLast("http-chunked", new ChunkedWriteHandler());//用于大数据的分区传输
        pipeline.addLast("http-handler", new HttpHandler());//设置http处理器
        pipeline.addLast("ws-handler", new WebSocketHandler());//设置websocket处理器
        pipeline.addLast("upgrade-handler", new FileUploadHandler());//设置websocket协议处理器
    }
}
